﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SQLite;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e) 
    {
        if (!IsPostBack)
        {
            new UDCPage().LoginOut();
            loginnameTxT.Text = "";
            passwordTxT.Text = "";
            //throw new Exception("test");
        }
    }

    protected void loginIn_Click(object sender, EventArgs e)
    {        
        if (ValidUser())
        {
            Response.Redirect("Desktop.aspx");
        }
        else
        {
            msg.Text = "用户名或者密码有误，请重试！";
        }
    }

    private bool ValidUser()
    {
        SQLiteParameter[] spc = {
        new SQLiteParameter("$loginname", DbType.String, 10),
        new SQLiteParameter("$password", DbType.String, 16)
        };
        spc[0].Value = loginnameTxT.Text.Trim();
        spc[1].Value = passwordTxT.Text.Trim();
        string sqlstr = "select uid from ud_user_t "
            + " where loginname = $loginname and password = $password and ifvalid = 1";
        object Res = SQLiteHelper.ExecuteScalar(sqlstr, spc);
        new UDCPage().Uid = (Res != null ? Int32.Parse(Res.ToString()) : 0);
        return Res != null;
    }
}